package org.rujue.modules.sys.entity;

import lombok.Data;
import org.hibernate.validator.constraints.Length;
import java.util.Date;
import com.fasterxml.jackson.annotation.JsonFormat;

import org.rujue.common.persistence.DataEntity;
import org.springframework.web.multipart.MultipartFile;

/**
 * 通用附件管理Entity
 * @author Mr.xu
 * @version 2023-11-13
 */
@Data
public class SysFile extends DataEntity<SysFile> {
	
	private static final long serialVersionUID = 1L;
	/** 宿主表ID */
	private String hostId;
	/** 宿主表IDS */
	private String hostIds;
	/** 宿主表名称 */
	private String hostTable;
	/** 文件名称 */
	private String fileName;
	/** 文件描述 */
	private String fileDesc;
	/** 文件路径 */
	private String filePath;
	/** 文件扩展名:docx、pdf.jpg... */
	private String fileExt;
	/** 文件大小 */
	private String fileSize;
	/** 目标日期 */
	private Date targetDate;
	/** 附件 */
	private MultipartFile file;

	public SysFile() {
		super();
	}

	public SysFile(String id){
		super(id);
	}

	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
	public Date getTargetDate() {
		return targetDate;
	}

	public void setHostIds(String hostIds) {
		// 如果hostIds前面没"0,"则追加
		if(!hostIds.startsWith("0,")){
			hostIds = "0," + hostIds;
		}
		// 如果hostIds后面没","则追加
		if(!hostIds.endsWith(",")){
			hostIds = hostIds + ",";
		}
		this.hostIds = hostIds;
	}
}